goog.provide('tipfy');
goog.provide('tipfy.XhrIo');

goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('goog.net.XhrIo');
goog.require("goog.structs.Map");
goog.require("goog.Uri.QueryData");

// There's no tab element but they are used in pages.
goog.require('goog.ui.Component.EventType');
goog.require('goog.ui.TabBar');

//var tipfy = tipfy || {};
//var tipfy.ui = tipfy.ui || {};
//tipfy.XhrIo = {};

tipfy.registry = {};

// XXX
tipfy.init = function() {
    goog.events.listen(window, goog.events.EventType.UNLOAD, function() {
        goog.events.removeAll();
    });
};

// XXX
tipfy.XhrIo.send = function(url, opt_callback, opt_method, opt_content,
    opt_headers, opt_timeoutInterval) {
    opt_headers = opt_headers || {};
    opt_headers['X-REQUESTED-WITH'] = 'XMLHttpRequest';
    if (opt_content) {
        opt_content = goog.Uri.QueryData.createFromMap(
            new goog.structs.Map(opt_content)).toString();
    }
    goog.net.XhrIo.send(url, opt_callback, opt_method, opt_content,
        opt_headers, opt_timeoutInterval);
};

// XXX
tipfy.SetEqualHeightContents = function(el1, el2) {
    el1 = goog.dom.getElement(el1);
    el2 = goog.dom.getElement(el2);

    var el1_size = goog.style.getContentBoxSize(el1),
        el2_size = goog.style.getContentBoxSize(el2),
        to_change = el1_size.height < el2_size.height ? el1 : el2,
        src_size = to_change == el1 ? el2_size : el1_size,
        dst_size = to_change == el1 ? el1_size : el2_size;

    dst_size.height = src_size.height;
    goog.style.setContentBoxSize(to_change, dst_size);
};
